#include <stdio.h>
#include <unistd.h>

// 测试创建子进程函数pid_t fork();
int main()
{
    int a = 0;
    printf("未创建子进程的变量a地址:%p\n",&a);
    pid_t pid = fork();
    if(-1 == pid)
    {
        //创建子进程失败
        return -1;
    }
    if(0 == pid)
    {
        //子进程
        printf("I am child, my pid：%d, ppid：%d\n",getpid(),getppid());
        a = 10;
        printf("子进程a：%d\n",a);
        printf("子进程的变量a地址:%p\n",&a);
        sleep(5);
    }
    else
    {
        //父进程        
        printf("I am father, my pid：%d, ppid：%d\n",getpid(),getppid());
        printf("父进程a：%d\n",a);
        printf("父进程的变量a地址:%p\n",&a);
        sleep(5);
    }

    return 0;
}
